Skip to content

layersvt: Make LayerBase built-in commands virtual behind Dispatch thunks - #58

Open
olehkuznetsov wants to merge 1 commit into
mainfrom
push-sztowlotqtlm
Open

olehkuznetsov wants to merge 1 commit into
mainfrom
push-sztowlotqtlm

Conversation

@olehkuznetsov

Copy link
Copy Markdown

Convert the 11 LayerBase built-in proc-addr, lifecycle, enumeration, and
tooling entry points from protected static C functions into protected
virtual member methods backed by private static C ABI Dispatch* thunks
and friend struct LayerEntrypoints. Route layer_entrypoints.cpp and
LayerBaseTestPeer through Dispatch* and add unit tests for virtual
overrides.

Test: ctest --test-dir build --output-on-failure
Change-Id: I706b3eb696edaf65203cc85ae62d42386a6a6964

…unks

Convert the 11 LayerBase built-in proc-addr, lifecycle, enumeration, and
tooling entry points from protected static C functions into protected
virtual member methods backed by private static C ABI Dispatch* thunks
and friend struct LayerEntrypoints. Route layer_entrypoints.cpp and
LayerBaseTestPeer through Dispatch* and add unit tests for virtual
overrides.

Test: ctest --test-dir build --output-on-failure
Change-Id: I706b3eb696edaf65203cc85ae62d42386a6a6964
VkLayerProperties* properties);
virtual VkResult EnumerateDeviceExtensionProperties(VkPhysicalDevice physical_device, const char* layer_name,
uint32_t* property_count, VkExtensionProperties* properties);
virtual VkResult GetPhysicalDeviceToolProperties(VkPhysicalDevice physical_device, uint32_t* tool_count,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This override is only reachable if HasToolProperties() returns true. GetKnownInstanceCommand returns DispatchGetPhysicalDeviceToolProperties only in that case. If a layer overrides GetPhysicalDeviceToolProperties but has no tool_properties in its manifest (and does not override HasToolProperties()), the override is never called, and nothing tells the author why.

Can we state this in the comment block above, and in the README note? For example: "Overriding GetPhysicalDeviceToolProperties takes effect only when HasToolProperties() returns true."


// Override to wrap a built-in command. Arguments arrive unchecked from the loader: handles can be VK_NULL_HANDLE and
// pointers can be null. An override of Create*/Destroy* must call the LayerBase implementation, which registers and
// releases the dispatch tables and runs the Pre*/Post* hooks.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small points about this comment:

  1. Every other protected virtual in this class has its own /** ... */ doc block. This one floating // block covers 11 methods. Per-method docs (or a doc block on the group) would be easier to find from an IDE hover.
  2. Overriding GetInstanceProcAddr / GetDeviceProcAddr now overlaps with GetLayerInstanceCommand / GetLayerDeviceCommand. Can you add one sentence on which one to use? For example: "Prefer GetLayerCommand to add intercepts; override GetProcAddr only to change lookup behavior itself." Without it, authors will use both styles.

static VkResult VKAPI_CALL GetPhysicalDeviceToolProperties(VkPhysicalDevice physical_device, uint32_t* tool_count,
VkPhysicalDeviceToolPropertiesEXT* tool_properties);
static VkResult GetPhysicalDeviceToolPropertiesWithDownstream(
VkResult GetPhysicalDeviceToolPropertiesWithDownstream(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just below this, GetKnownInstanceCommand / GetKnownDeviceCommand are still static and look up the layer with Get(). But their only callers are now the non-static GetInstanceProcAddr / GetDeviceProcAddr. That gives two paths in one call: this for the outer method and Get() for the inner lookup (GetLayerInstanceCommand, HasToolProperties). They are the same object in production, but a test that constructs a second layer could see them differ.

Suggest making both helpers non-static members that use this, and removing the AssertLayerInitialized() / Get() lines in them. That matches what this PR already does for EnumerateDeviceExtensionPropertiesWithDownstream and GetPhysicalDeviceToolPropertiesWithDownstream.

Comment thread layersvt/common/README.md
PFN_vkVoidFunction GetLayerDeviceCommand(VkDevice device, const char* command_name) override;

// Built-in commands (CreateInstance, DestroyDevice, Enumerate*, etc.) can also be wrapped
// by overriding their virtual methods on LayerBase.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you copy the contract from layer_base.h into this example? An override of Create* / Destroy* must call the LayerBase:: implementation, or the dispatch tables are not registered or released and the Pre*/Post* hooks do not run. This README is the main authoring guide, so a short example of an override that calls the base method would be useful here:

VkResult CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* ci,
                      const VkAllocationCallbacks* alloc, VkDevice* device) override {
  // ... custom logic ...
  return LayerBase::CreateDevice(gpu, ci, alloc, device);
}

}

// Built-in commands queried via GIPA return Dispatch* thunks and invoke the virtual overrides when called.
TEST(LayerEntrypointsTest, InstanceProcAddrThunksRouteThroughVirtualOverrides) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage gaps (non-blocking):

  1. No test covers the documented contract: an override that calls LayerBase::CreateInstance / CreateDevice / Destroy* still registers and releases the dispatch tables and runs the Pre*/Post* hooks. All the overrides here short-circuit and never call the base methods. One test that wraps and calls the base method (with the existing test_layer_base.cpp chain-info helpers) would protect the main use case of this PR.
  2. The GIPA-returned thunks for vkGetInstanceProcAddr, vkEnumerateInstance*Properties and vkEnumerateDevice*Properties are not called here. Only the exported symbols are tested for those commands.

TEST(LayerEntrypointsTest, ExportedSymbolsRouteThroughVirtualOverrides) {
LayerManifest manifest{
.layer_name = "VK_LAYER_TEST_Entrypoints",
.tool_properties = VkPhysicalDeviceToolPropertiesEXT{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: tool_properties is not used in this test because tool properties are not queried here. Also, the same manifest and layer setup is copied into three tests. A small TEST_F fixture (or a helper that returns the manifest) would reduce the repetition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants